package com.yunpai.SingleMolde;

/**
 * 懒汉式(不安全)
 */
public class SinglelazyType03 {
    private static SinglelazyType03 singlelazyType03;

    private SinglelazyType03() {

    }

    /**
     * 当调 getInstance方法的时候,才会创建单例对象 ,懒加载
     */
    public static synchronized SinglelazyType03 getInstance() {
        if (singlelazyType03 == null) {
            singlelazyType03 = new SinglelazyType03();
        }
        return singlelazyType03;
    }
}


class Main3 {


    /**
     * 测试
     */
    public static void main(String[] args) {
        SinglelazyType03 singlelazyType = SinglelazyType03.getInstance();
        SinglelazyType03 singlelazyType1 = SinglelazyType03.getInstance();
        System.out.println(singlelazyType == singlelazyType1);
        System.out.println("singlelazyType.hashCode=" + singlelazyType.hashCode());
        System.out.println("singlelazyType1.hashCode=" + singlelazyType1.hashCode());
        //结果相同,说明是同一个对象实列
    }
}
